package demo3;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何华树
 * Date: 2024-09-02
 * Time: 11:12
 */
public class Computer {
    public void open() {
        System.out.println("开机");
    }
    public void close() {
        System.out.println("关机");
    }
    public void useUSBdevice(USB usb) {
        usb.OpenDevice();
        if(usb instanceof Mouse) {
            //判断 usb 这个引用是否来自于 Mouse类型
            Mouse mouse = (Mouse)usb;
            mouse.click();
        } else if (usb instanceof Keyboard) {
            Keyboard keyboard = (Keyboard) usb;
            keyboard.input();
        }
        usb.CloseDevice();
    }

}
